<?php
session_start();
if ($_SESSION['Status'] != '1') {
    header('Location: signup.php');
}
$id = $_SESSION['name'];

$query = "SELECT * FROM acedamic_year WHERE Users_email = '$id'";
include "dbconnection.php";
if (!$result = mysql_query($query))
    die("Could not execute query<br/>" . mysql_error());
include "dbconnectionclose.php";
?>
<div class="page">
        <div class="page-header" >
        <div class="page-header-content">
            <h1>Classes</h1>
        </div>
    </div>
    <div class="page snapped">
        <div class="page-region">
            <div class="page-region-content">
            </div>
        </div>
    </div>
    <div class="page fill">
        <div class="page-region">
            <div class="page-region-content">
                <div class="grid">
                    <div class="row">
                        <div class="clearfix">
                            <div class="span4">
                                <div class="tile double  bg-color-lighten" style="outline: 0px;">
                                    <div class="tile-content">
                                        <?php
                                        for ($counter = 0; $row = mysql_fetch_array($result); $counter++) {
                                            $y_id = $row['ayear_id'];
                                            print("<blockquote onclick='details()' class='tertiary-text padding10 bg-color-white fg-color-blueDark' style='margin-bottom: 10px;'>$row[ayear_name]</blockquote>");
                                        }
                                        ?>
                                    </div>
                                    <div class="brand">
                                        <div class="name fg-color-darken" style="font-size: 15pt;">Academic Year</div>
                                        <div class="badge">
                                            <i class="icon-plus fg-color-darken" id="addAcYr"></i>
                                        </div>
                                    </div>
                                </div>

                                <div class="tile double double-vertical bg-color-lighten outline-color-lighten" style="outline: 0px;">
                                    <div class="tile-content">
                                    </div>
                                    <div class="brand">
                                        <div class="name fg-color-darken" style="font-size: 15pt;">Semester</div>
                                        <div class="badge">
                                            <i class="icon-plus fg-color-darken" id="addSem"></i>
                                        </div>
                                    </div>
                                </div>
                                <!-- Add new Semester Dialog box - begin -->
                                <!-- Add new Semester Dialog box - begin -->
                            </div>

                            <div class="tile double triple-vertical bg-color-lighten outline-color-lighten" style="outline: 0px;">
                                <div class="tile-content">
                                </div>
                                <div class="brand">
                                    <div class="name fg-color-darken" style="font-size: 15pt;">Subject</div>
                                    <div class="badge">
                                        <i class="icon-plus fg-color-darken" id="addSub"></i>
                                    </div>
                                </div>
                            </div>
                            <!-- Add new Subject Dialog box - begin -->

                            <!-- Add new Subject Dialog box - collapse -->

                        </div>

                        <div class="grid">
                            <div class="tile double triple-vertical bg-color-lighten outline-color-lighten" style="outline: 0px;">
                                <div class="tile-content">
                                </div>
                                <div class="brand">
                                    <div class="name fg-color-darken" style="font-size: 15pt;">Classes</div>
                                    <div class="badge">
                                        <i class="icon-plus fg-color-darken" id="addClass"></i>
                                    </div>
                                </div>
                                <!-- Add new class Dialog box - begin -->

                                <!-- Add new class Dialog box - collapse -->
                            </div>

                            <div class="tile double triple-vertical bg-color-lighten outline-color-lighten" style="outline: 0px;">
                                <div class="tile-content">
                                    <div class="brand">
                                        <div class="name fg-color-darken" style="font-size: 15pt;">Details</div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function(){
        $('#addAcYr').click(function(e) {
            $.Dialog({
                'title'      : 'Add Academic Year',
                'draggable': true,
                'content'    : '<form id="acyr"><table>'+
                    '<tr><td><p><label>Academic Year:</label></td><td><input class="with-helper input-control text" name="acYrName" type="text" autofocus="" placeholder="ex: 2012/2013"/></p></td></tr>'+
                    '<tr><td><p><label>Start Date:</label></td><td><input id="" type="text" name="startDate" placeholder="Start Date" /></p></td></tr>'+
                    '<tr><td><p><label>End Date:</label></td><td><input type="text" autofocus="" name="endDate" placeholder="End Date"/></p></td></tr>'+
                    '</table></form>',
                'buttons'    : {
                    'Ok'    : {
                        'action': function() {
                            var data_acyr = $('#acyr').serialize();
                            $.ajax({
                                url:'manageacyr.php',
                                type:"POST",
                                data: data_acyr,
                                success:function(data){
                                    var pagedata = $(data);
                                    if(pagedata.find("h4").html()=="Successful!"){
                                        alert("success");
                                        alert(pagedata.html());
                                    }else{
                                        alert(pagedata.html());
                                    }
                                }
                            });
                        }
                    },
                    'Cancel'     : {
                        'action': function() {}
                    }
                }
            });
        });
        
        $('#addSem').click(function(e) {
            $.Dialog({
                'title'      : 'Add Semester',
                'draggable': true,
                'content'    :'<div class="span6"><form id=sem><table>'+
                    '<tr><td><p><label>Semester:</label></td><td><input class="with-helper input-control text" name="SemName" type="text" autofocus="" placeholder="Semester"/></p></td></tr>'+
                    '<tr><td><p><label>Start Date:</label></td><td><input type="text" autofocus="" name="startDate" placeholder="Start Date"/></p></td></tr>'+
                    '<tr><td><p><label>End Date:</label></td><td><input type="text" autofocus="" name="endDate" placeholder="End Date"/></p></td></tr>'+
                    '<tr><td><p><label>Academic Year:</label></td><td><select name="acYr" ><option>vlaue01</option><option>value02</option><option>value03</option></select></p>'+
                    '<tr><td><p><label>Description:</label></td><td><input type="text" autofocus="" name="Desc" placeholder="End Date"/></p></td></tr>'+
                    '</table></form></div>',
                'buttons'    : {
                    'Ok'    : {
                        'action': function() {
                            var data_sem = $('#sem').serialize();
                            alert(data_sem);
                            $.ajax({
                                url:'manageSem.php',
                                type:"POST",
                                data: data_sem,
                                success:function(data){
                                    var pagedata = $(data);
                                    if(pagedata.find("h4").html()=="Successful!"){
                                        alert("success");
                                        alert(pagedata.html());
                                    }else{
                                        alert(pagedata.html());
                                    }
                                }
                            });
                        }
                    },
                    'Cancel'     : {
                        'action': function() {}
                    }
                }
            });
        });
        
        $('#addSub').click(function(e) {
            $.Dialog({
                'title'      : 'Add Subject',
                'draggable': true,
                'content'    : '<html><body><div class="span5"><form id="sub"><table>'+
                    '<tr><td><p><label>Subject:</label></td><td><input class="with-helper input-control text" id="acYrName" type="text" autofocus="" placeholder="Subject"/></p></td></tr>'+
                    '<tr><td><p><label>Subject ID:</label></td><td><input type="text" autofocus="" id="startDate" placeholder="IMMG0000"/></p></td></tr>'+
                    '<tr><td><p><label>Semester:</label></td><td><select><option>vlaue01</option><option>value02</option><option>value03</option></select></p>'+
                    '<tr><td><p><label>Description:</label></td><td><input type="text" autofocus="" id="description"/></p></td></tr>'+
                    '</table></form></div></body></html>',
                'buttons'    : {
                    'Ok'    : {
                        'action': function() {
                            var data_sem = $('#sub').serialize();
                            alert(data_sem);
                            $.ajax({
                                url:'manageSem.php',
                                type:"POST",
                                data: data_sem,
                                success:function(data){
                                    var pagedata = $(data);
                                    if(pagedata.find("h4").html()=="Successful!"){
                                        alert("success");
                                        alert(pagedata.html());
                                    }else{
                                        alert(pagedata.html());
                                    }
                                }
                            });
                        }
                    },
                    'Cancel'     : {
                        'action': function() {}
                    }
                }
            });
        });
        
        $('#addClass').click(function(e) {
            $.Dialog({
                'title'      : 'Add Class',
                'draggable'  : true,
                'content'    : '<form><table style="border-color: white;">'+
                    '<tr><td><p><label>Subject:</label></td><td><input class="with-helper input-control text" id="subject" type="text" autofocus="" placeholder="ex: 2012/2013"/></p></td></tr>'+
                    '<tr><td><p><label>Date:</label></td><td><input type="text" autofocus="" name="Date" placeholder=""/></p></td></tr>'+
                    '<tr><td><p><label>Start time:</label></td><td><input type="text" autofocus="" name="s_time" placeholder=""/></p></td></tr>'+
                    '<tr><td><p><label>End time:</label></td><td><input class="with-helper input-control text" name="e_time" type="text" autofocus="" placeholder=""/></p></td></tr>'+
                    '</table></form>',
                'buttons'    : {
                    'Ok'    : {
                        'action': function() {
                        }
                    },
                    'Cancel'     : {
                        'action': function() {}
                    }
                }
            });
        });
    });
                                   
</script>
